نمایش نتایج: از شماره 1 تا 1 از مجموع 1
Like Tree1نفر پسندیدند
  • 1 ارسال توسط NIIT

موضوع: پیدا کردن بزرگترین و کوچکترین مقدار با لیستهای پیوندی

  1. #1
    مدیر بازنشسته
    تاریخ عضویت
    2011 June
    محل سکونت
    گرگان
    ارسال ها
    1,170
    تشکر
    62
    تشکر شده 1,587 بار در 809 پست
    نوشته های وبلاگ
    49


    آيا اين پست براي شما سودمند بود؟ بله | خیر

    پیدا کردن بزرگترین و کوچکترین مقدار با لیستهای پیوندی

    کلاس:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;

    namespace STUDENT
    {
    public class Linklist
    {
    public node first = new node();
    public node current = new node();
    public node max = new node();
    public node min = new node();
    // public string print;
    public string more;
    public string less;
    public node b = new node();
    public bool a;
    public Linklist()
    {
    first = null;

    }
    public void add(string name,int id,int average)
    {
    node n = new node(name,id,average);

    if (first == null)
    {
    a = true;
    first = n;
    current = first;
    }
    else
    {
    a = false;
    current = first;
    while (current.Next != null)
    current = current.Next;
    current.Next = n;
    }
    }

    public node FindMax()
    {
    current = first;
    max = current;
    while(current.Next!=null)
    {
    if (current.Next.Average > current.Average)
    {
    max = current.Next;
    current = current.Next;
    }
    else
    current = current.Next;

    }
    return max;

    }
    public node FindMin()
    {
    current = first;
    min = current;
    while (current.Next != null)
    {
    if (current.Next.Average < current.Average)
    {
    min = current.Next;
    current = current.Next;
    }
    else
    {

    current = current.Next;
    }
    }
    return min;

    }
    public string FindMore(int avg)
    {
    more = "";
    current = first;
    while (current!= null)
    {
    if (current.Average <= avg)
    current = current.Next;
    else
    {
    more = more + current.Name+" : "+current.Id+" / "+current.Average+"\n";
    current = current.Next;
    }

    }
    return more;

    }
    public String FindLess(int avg)
    {
    less = "";
    current = first;
    while (current != null)
    {
    if (current.Average >= avg)
    current = current.Next;
    else
    {
    less = less + current.Name + " : " + current.Id + " / " + current.Average + "\n";
    current = current.Next;
    }
    }
    return less;
    }



    }
    }


    فراخونی:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Media;

    namespace STUDENT
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();

    }
    Linklist l = new Linklist();


    private void btnAdd_Click(object sender, EventArgs e)
    {

    if (txtName.Text != "" && txtId.Text != "")
    {
    string a = txtName.Text;
    int b = Convert.ToInt32(txtId.Text);
    int c = Convert.ToInt32(txtAv.Text);
    l.add(a, b, c);

    if (l.a == true)
    r1.Text = l.current.Name + l.current.Id + l.current.Average;
    else if (l.a == false)
    r1.Text = l.current.Next.Name + l.current.Next.Id + l.current.Next.Average;
    txtName.Text = "";
    txtId.Text = "";
    txtAv.Text = "";

    }
    else
    MessageBox.Show("please fill in the blanks first");
    }
    private void button3_Click(object sender, EventArgs e)
    {
    try
    {
    l.FindMax();
    txtMaxName.Text = l.max.Name;
    txtMaxId.Text = Convert.ToString(l.max.Id);
    txtMaxAv.Text = Convert.ToString(l.max.Average);
    }
    catch { }
    }

    private void button4_Click(object sender, EventArgs e)
    {
    try
    {
    l.FindMin();
    txtMinName.Text = l.min.Name;
    txtMinId.Text = Convert.ToString(l.min.Id);
    txtMinAv.Text = Convert.ToString(l.min.Average);
    }
    catch { }
    }

    private void button7_Click(object sender, EventArgs e)
    {
    if (txtMore.Text == "")
    MessageBox.Show("Insert the average first");
    else
    {
    l.FindMore(Convert.ToInt32(txtMore.Text));
    r3.Text = l.more;
    }

    }

    private void button8_Click(object sender, EventArgs e)
    {
    if (txtLess.Text == "")
    MessageBox.Show("Insert the average first");
    else
    {
    l.FindLess(Convert.ToInt32(txtLess.Text));
    r3.Text = l.less;
    }
    }







    }
    }


    سوالی بود ،بفرمایین
    بااحترام

    موضوعات مشابه:
    Hossein این نویسه را میپسندد.
    آرامش محصول تفکر نیست! آرامش هنر نیندیشیدن به انبوه مسائلیست که ارزش فکر کردن ندارد...

 

 

کاربران برچسب خورده در این موضوع

علاقه مندی ها (Bookmarks)

علاقه مندی ها (Bookmarks)

مجوز های ارسال و ویرایش

  • شما نمیتوانید موضوع جدیدی ارسال کنید
  • شما امکان ارسال پاسخ را ندارید
  • شما نمیتوانید فایل پیوست کنید.
  • شما نمیتوانید پست های خود را ویرایش کنید
  •  


Powered by vBulletin
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.6.0
Persian Language By Ustmb.ir
این انجمن کاملا مستقل بوده و هیچ ارتباطی با دانشگاه علوم و فنون مازندران و مسئولان آن ندارد..این انجمن و تمامی محتوای تولید شده در آن توسط دانشجویان فعلی و فارغ التحصیل ادوار گذشته این دانشگاه برای استفاده دانشجویان جدید این دانشگاه و جامعه دانشگاهی کشور فراهم شده است.لطفا برای اطلاعات بیشتر در رابطه با ماهیت انجمن با مدیریت انجمن ارتباط برقرار کنید
ساعت 07:05 AM بر حسب GMT +4 می باشد.